#include "bcstmainthread.h"
#include <QDebug>
#include "./qzmthrift/thrifthandler.h"


QMutex BcstMainThread::g_mutex_flag_openRtBCST;
QMutex BcstMainThread::g_mutex_flag_closeRtBCST;

bool BcstMainThread::g_flag_openRtBCST{false};
bool BcstMainThread::g_flag_closeRtBCST{false};

BcstMainThread::BcstMainThread(QObject *parent) : QThread (parent)
{
}

void BcstMainThread::enableThread()
{
    m_isRun = true;
    this->start();
}

void BcstMainThread::disableThread()
{
    m_isRun = false;
}

void BcstMainThread::run()
{
    qDebug()<<"Enter BcstMainThread::run()";
    while(m_isRun)
    {
        if(BcstMainThread::g_flag_openRtBCST==true){
            BcstMainThread::g_flag_openRtBCST=false;
            //openRtBCST();
            qDebug()<<"BcstMainThread object implement openRtBCST()";
            QMutexLocker locker(&ThriftHandler::g_mutex_flag1);
            ThriftHandler::g_flag1 = true;
        }
        else if(BcstMainThread::g_flag_closeRtBCST==true){
            BcstMainThread::g_flag_closeRtBCST=false;
            //closeRtBCST();
            qDebug()<<"BcstMainThread object implement closeRtBCST()";
            QMutexLocker locker(&ThriftHandler::g_mutex_flag1);
            ThriftHandler::g_flag1 = true;
        }

        QThread::msleep(300);
    }
}

void BcstMainThread::handle_openRtBCST()
{
    qDebug()<<"Enter handle_openRtBCST()";
}

void BcstMainThread::handle_closeRtBCST()
{
    qDebug()<<"Enter handle_closeRtBCST()";
}





